<?php

$title = 'SMILEYS';
include_once('system/core.php');
include_once('system/head.php');

echo '<div class="title"><a href="smile.php"><b>' . $lang['smiley'] . '</b></a></div>';

$case=htmlspecialchars(trim($_GET['a']));

switch($case){

default:

        $dir = glob($root . 'files/images/smileys/*', GLOB_ONLYDIR);
        foreach ($dir as $val) {
            $cat = explode('/', $val);
            $cat = array_pop($cat);
            
                $smileys_cat[$cat] = ucfirst($cat);
            
        }
        asort($smileys_cat);
        $i = 0;
        foreach ($smileys_cat as $key => $val) {
            echo '<div id="imenu" class="small">';
            echo '<a class="url" href="smile.php?a=watch&amp;cat=' . urlencode($key) . '">' . htmlspecialchars($val) . ' (' . count(glob($root . 'files/images/smileys/' . $key . '/*.{gif,jpg,png}', GLOB_BRACE)) . ')</a> ' .
                 ' ';
            echo '</div>';
            ++$i;
        }
        break;

    case 'watch':
      
        $dir = glob($root . 'files/images/smileys/*', GLOB_ONLYDIR);
        foreach ($dir as $val) {
            $val = explode('/', $val);
            $cat_list[] = array_pop($val);
        }
        $cat = isset($_GET['cat']) && in_array(trim($_GET['cat']), $cat_list) ? trim($_GET['cat']) : $cat_list[0];
        $smileys = glob($root . 'files/images/smileys/' . $cat . '/*.{gif,jpg,png}', GLOB_BRACE);
        $total = count($smileys);


        if ($total) {
                 
                     //Моя навигация
    $page = (isset($_GET['p'])) ? intval($_GET['p']) : 1 ; 
    $allpage = ceil($total/$kmess);
    $start = $page*$kmess - $kmess; 
    $end = $start + $kmess;
    if ($end > $total) $end = $total;
                 
                     for ($i = $start; $i < $end; $i++) {
                $smile = preg_replace('#^(.*?).(gif|jpg|png)$#isU', '$1', basename($smileys[$i], 1));
                echo '<div id="imenu" class="small">';
                echo '<img src="'.$root.'files/images/smileys/' . $cat . '/' . basename($smileys[$i]) . '" alt="" />&#160;.' . $smile . '. ' . $lng['lng_or'] . ' .' . functions::trans($smile) . '.';
                echo '</div>';
            }
               } else {
            echo '<div class="menu"><p>'.$lang['empty'].'!</p></div>';
        }
        
        echo '<div class="small">' . $lang['total'] . ': ' . $total . '</div>';

            if($total>$kmess){
    echo '<p>';
    functions::navigation($allpage,"smile.php?a=watch&amp;cat=$cat&amp;p={p}",1);  
echo '</p>';}

        break;
        
        }
        
echo '<div class="title"><a href="smile.php">' . $lang['smiley'] . '</a></div>';
include_once('system/foot.php');
?>